const mysql = require('../mysql/db')

/**
 *
 */
async function registerApp(socket, message) {

  let data = await mysql('daka').select('*').where({erp: message.erp})
  if (data && data.length > 0) {
    data = await mysql('daka').where({erp: message.erp})
      .update({
        status: true,
      })
  } else {
    data = await mysql('daka').insert({
      erp: message.erp,
      status: true,
    })
  }
  socket.emit(`back_${message.erp}`, data)
}

/**
 *
 */
async function offlineApp(socket, message) {


  const data = await mysql('daka').where({erp: message.erp})
    .update({
      status: false,
    })
  socket.emit(`back_${message.erp}`, data)
}

module.exports = {
  registerApp,
  offlineApp,
}
